<?php
/**
 * Created by : PhpStorm
 * User: 阿城 <479468212@qq.com>
 * Date: 2019/12/27
 * Time: 13:02
 */

namespace app\api\controller;

use app\api\controller\Base;
use app\api\model\User;
use app\api\model\UserData;
use app\util\Tools;

class Profile extends Base
{
    /**
     * @OA\Get(
     *   path="/api/profile/getUserInfo",
     *   tags={"用户相关"},
     *   summary="获取用户信息",
     *   @OA\Parameter(ref="#/components/parameters/AppClientVersion"),
     *   @OA\Parameter(ref="#/components/parameters/AppDeviceType"),
     *   @OA\Response(
     *     response=200,
     *     description="Success",
     *     @OA\JsonContent( type="array", @OA\Items(ref="#/components/schemas/response" ) )
     *   ),
     *   @OA\Response(response="500", description="服务器错误"),
     *   security={{"App-Login-Token": ""}}
     * )
     */
    public function getUserInfo() {
        $this->success('成功',$this->userInfo);
    }

    /**
     * @OA\Get(
     *   path="/api/profile/messageLog",
     *   tags={"用户相关"},
     *   summary="消息记录",
     *   @OA\Parameter(ref="#/components/parameters/AppClientVersion"),
     *   @OA\Parameter(ref="#/components/parameters/AppDeviceType"),
     *   @OA\Parameter(name="type",in="query",description="1系统消息、2私信", @OA\Schema( type="string" )),
     *   @OA\Parameter(ref="#/components/parameters/order"),
     *   @OA\Parameter(ref="#/components/parameters/size"),
     *   @OA\Parameter(ref="#/components/parameters/page"),
     *   @OA\Response(
     *     response="200",
     *     description="返回JSON",
     *     @OA\MediaType(
     *      mediaType="application/json",
     *      @OA\Schema(
     *         @OA\Property(property="code", type="number",description="状态码"),
     *         @OA\Property(property="msg", type="string",description="提示消息"),
     *         @OA\Property(property="data", type="object",description="数据列表",@OA\Items),
     *      )
     *    )
     *   ),
     *   @OA\Response(response="500", description="服务器错误"),
     *   security={{"App-Login-Token": ""}}
     * )
     */
    public function messageLog()
    {
        $limit       = $this->request->get('size', config('easyApi.ADMIN_LIST_DEFAULT'));
        $start       = $this->request->get('page', 1);
        $order       = $this->request->get('order','create_time DESC');
        $type        = $this->request->get('type');
        $MessageLogModel  = new MessageLog();
        if(!empty($type)){
            $MessageLogModel = $MessageLogModel->where('type','=',$type);
        }
        $listObj = $MessageLogModel->where(['status'=>1,'uid'=>$this->userId])->order($order)->paginate($limit, false)->toArray();
        $this->success('成功', [
            'type' => MessageLog::$typeArr,
            'list'  => $listObj['data'],
            'count' => $listObj['total']
        ]);
    }
}
